M98 P"0:/sys/led/resetstatus.g"

; Relax all XYU motors before manual movement test (in case of restart without homing)
M84 XYU
G4 S1

M564 H0

M291 R"Move Tools by Hand Test" P"Manually move both tool heads along X, Y, and U axes.<br><br>Check that movement is smooth and without binding.<br><br>Pay attention to any unusual resistance or sounds." S4 K{"Movement was Smooth","Cancel"}
if input == 1
    abort "Test cancelled by user"

M291 R"Move XYU Axes Manually" P"Manually move both tool heads by hand.<br>Test all axes: X (left tool), U (right tool), and Y (Cross Bar)." S3 X1 Y1 U1

M302 P0

M564 H0
M291 R"Z - Motor Connection Test" P"Each motor will move in sequence: Left, Right, Rear" S4 K{"Test","Raise Build Plate","Skip","Cancel"}
if input == 1
    ; Raise Up option - move Z-axis up by 25mm
    M564 H0 ; Ensure movement without homing is allowed
    G91 ; Set to relative positioning
    G1 Z-25 F18000 ; Move Z-axis up by 25mm (negative Z = up)
    G90 ; Set to absolute positioning
    M400 ; Wait for movement to complete
    M291 R"Z - Motor Connection Test" P"Z-axis raised by 25mm.<br><br>Each motor will move in sequence: Left, Right, Rear" S4 K{"Test","Skip","Cancel"}
    if input == 1
        M99
    elif input == 2
        abort "Test cancelled by user"
elif input == 2
    M99
elif input == 3
    abort "Test cancelled by user"

M913 Z75 ; Reduce Z-axis current to 75% for safe motor testing
M17 Z             ; energize all three leadscrews: a V/W/A move only wakes its own driver

M584 P7           ; un-hide V/W/A
G92 V0 W0 A0      ; re-establish their homed state at the current position

; Move Left lead screw
G91               ; set to relative positioning
G1 F18000 W10    ; move 10mm down
G1 F18000 W-20     ; move 20mm up
G1 F18000 W10    ; move 10mm down back to original position
G90               ; set to absolute positioning

M400

; Move Right lead screw
G91               ; set to relative positioning
G1 F18000 V10    ; move 10mm down
G1 F18000 V-20     ; move 20mm up
G1 F18000 V10    ; move 10mm down back to original position
G90               ; set to absolute positioning

M400

; Move Rear lead screw
G91               ; set to relative positioning
G1 F18000 A10    ; move 10mm down
G1 F18000 A-20     ; move 20mm up
G1 F18000 A10    ; move 10mm down back to original position
G90               ; set to absolute positioning

M400
M584 P4           ; hide V/W/A again (Z remains mapped to 1.0:1.1:1.2 throughout)
M913 Z100 ; Reset Z-axis current to 100%

M564 H1
